﻿using System;
using WebSocket.App_Code.Common;
using System.Data;
using System.Data.SQLite;

namespace WebSocket.App_Code.Model
{
    public class MsgToUsers
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int id;

        /// <summary>
        /// 信息ID
        /// </summary>
        public int MsgID;

        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserID;

        /// <summary>
        /// 状态
        /// </summary>
        public string RecordStatus;

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="type">删除类型</param>
        /// <returns></returns>
        public int Delete(MsgToUsersDeleteType type)
        {
            string sqlStr = "update MsgToUsers set RecordStatus='InActive' where ";
            SQLiteParameter[] sp = new SQLiteParameter[1];
            switch (type)
            {
                case MsgToUsersDeleteType.id:
                    sqlStr += "id=@id";
                    sp[0] = new SQLiteParameter("@id", DbType.UInt32);
                    sp[0].Value = id;
                    break;
                case MsgToUsersDeleteType.MsgID:
                    sqlStr += "MsgID=@MsgID";
                    sp[0] = new SQLiteParameter("@MsgID", DbType.UInt32);
                    sp[0].Value = MsgID;
                    break;
                case MsgToUsersDeleteType.UserID:
                    sqlStr += "UserID=@UserID";
                    sp[0] = new SQLiteParameter("@UserID", DbType.UInt32);
                    sp[0].Value = UserID;
                    break;
                default: break;
            }
            return SQLiteHelper.ExecuteNonQuery(sqlStr, sp);
        }
    }

    /// <summary>
    /// SocketMsg表的删除类型
    /// </summary>
    public enum MsgToUsersDeleteType
    {
        /// <summary>
        /// 主键
        /// </summary>
        id=0,

        /// <summary>
        /// 信息ID
        /// </summary>
        MsgID = 1,

        /// <summary>
        /// 用户ID
        /// </summary>
        UserID = 2
    }
}